package cn.kent.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String CLUSTER_QUEUE_NAME = "cluster_queue_name";
    public static final String CLUSTER_EXCHANGE_NAME = "cluster_exchange_name";

    @Bean
    Queue msgQueue() {
        return new Queue(CLUSTER_QUEUE_NAME, true, false, false);
    }

    @Bean
    DirectExchange msgExchange() {
        return new DirectExchange(CLUSTER_EXCHANGE_NAME, true, false);
    }

    @Bean
    Binding msgBinding() {
        return BindingBuilder.bind(msgQueue())
                .to(msgExchange())
                .with(CLUSTER_QUEUE_NAME);
    }
}
